package LeetCode.LeetCode2;

/**
 * 搜索插入位置
 */
public class Num35 {
    public int searchInsert(int[] nums, int target) {
        if(nums.length == 1){
            if(nums[0] >= target) {
                return 0;
            }else{
                return 1;
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if(target < nums[0]){
                return 0;
            }
            if(nums[i] == target){
                return i;
            }else if(nums[i] > target) {
                return i;
            }
        }
        return nums.length;
    }
}
